package com.atguigu.dga.governance.mapper;

import com.atguigu.dga.governance.bean.GovernanceMetric;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.*;

/**
 * <p>
 * 考评指标参数表 Mapper 接口
 * </p>
 *
 * @author tubage
 * @since 2024-03-16
 */
@Mapper
@DS("dga")
public interface GovernanceMetricMapper extends BaseMapper<GovernanceMetric> {
    @Select("select\n" +
            "    id, metric_name, metric_code, metric_desc, governance_type, metric_params_json, governance_url, skip_assess_tables, is_disabled\n" +
            "    from governance_metric\n" +
            "where metric_code = #{metricCode}")
    GovernanceMetric selectByCode(String metricCode);

    @Delete("delete\n" +
            "from governance_metric\n" +
            "where metric_code = #{metricCode}")
    void deleteByMetricCode(String metricCode);

    @Update("update governance_metric\n" +
            "set is_disabled = #{isDisabled}\n" +
            "where metric_code = #{metricCode}")
    void disableByCode(String metricCode, Long isDisabled);

    @Update("update governance_metric\n" +
            "set\n" +
            "    metric_name=#{metricDTO.metricName},\n" +
            "    metric_desc=#{metricDTO.metricDesc},\n" +
            "    governance_type=#{metricDTO.governanceType},\n" +
            "    metric_params_json=#{metricDTO.metricParamsJson},\n" +
            "    governance_url=#{metricDTO.governanceUrl},\n" +
            "    skip_assess_tables=#{metricDTO.skipAssessTables},\n" +
            "    is_disabled=#{metricDTO.isDisabled}\n" +
            "where metric_code = #{metricDTO.metricCode}")
    void updateMetricByCode(@Param("metricDTO") GovernanceMetric metricDTO);

}
